<!DOCTYPE html>
<html lang="en">
<style>
    ul.group-list li {
        white-space: nowrap;float: left;
        width: 150px; height: 25px;
        padding: 3px 5px;list-style-type: none;
        list-style-position: outside;border: 0px;margin: 0px;
    }
    input[type=checkbox], input[type=radio] {
        display: inline-block;
    }

    .fileinput-button {
        position: relative;
        display: inline-block;
        overflow: hidden;
    }

    .fileinput-button input{
        position: absolute;
        left: 0px;
        top: 0px;
        opacity: 0;
        -ms-filter: 'alpha(opacity=0)';
    }
</style>
<link href="/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
{include file="Public/head"}

<body data-type="widgets">
<!--<script src="/daterangepicker/jquery-3.2.1.min.js" type="text/javascript"></script>-->
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper" >
        <div class="row-content am-cf">
            <div class="row">

                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">修改广告</div>
                            <div class="widget-function am-fr">
                                <a href="javascript:;" class="am-icon-cog"></a>
                            </div>
                        </div>
                        <div class="widget-body am-fr">
                            <form id="roleform"  form="submit" class="am-form tpl-form-border-form tpl-form-border-br">
                                <div class="am-form-group">
                                    <label for="user-name" class="col-sm-2 control-label">广告名称 </label>
                                    <div class="am-u-sm-9">
                                        <input type="text" class="tpl-form-input" name="ad_name" id="ad_name" value="{$res.ad_name}">
                                        <input type="text" id="ad_id" value="{$res.ad_id}" style="display: none">
                                        <small></small>
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <label for="user-name" class="col-sm-2 control-label">广告类型 </label>
                                    <div class="col-sm-3">
                                        <select name="media_type" id="media_type" class="input-sm">
                                            <option value="0">图片</option>
                                            <option value="1">flash</option>
                                        </select>
                                        <small></small>
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <label for="user-name" class="col-sm-2 control-label">广告位置 </label>
                                    <div class="col-sm-3">
                                        <select class="form-control" name="pid" id="pid">
                                            {volist name='ad_position_list' id='vo'}
                                            <option value="{$vo.position_id}" {if condition="$res['pname'] eq $vo['position_name']"}selected{/if} >
                                                {$vo.position_name}
                                            </option>
                                            {/volist}
                                        </select>
                                        <small></small>
                                    </div>
                                </div>

                                <!--<div class="am-form-group">-->
                                    <!--<label for="user-name" class="col-sm-2 control-label">开始日期 </label>-->
                                    <!--<div class="am-u-sm-9">-->
                                        <!--<div class="input-prepend input-group">-->
                                    <!--<span class="add-on input-group-addon">-->
                                            <!--<i class="glyphicon glyphicon-calendar fa fa-calendar">-->
                                            <!--</i>-->
                                    <!--</span>-->
                                            <!--<input type="text" class="form-control" id="start_time" name="publish_time" value="{$res.start_time}">-->
                                        <!--</div>-->
                                    <!--</div>-->
                                <!--</div>-->

                                <!--<div class="am-form-group">-->
                                    <!--<label for="user-name" class="col-sm-2 control-label">结束时间 </label>-->
                                    <!--<div class="am-u-sm-9">-->
                                        <!--<div class="input-prepend input-group">-->
                                    <!--<span class="add-on input-group-addon">-->
                                            <!--<i class="glyphicon glyphicon-calendar fa fa-calendar">-->
                                            <!--</i>-->
                                    <!--</span>-->
                                            <!--<input type="text" class="form-control" id="end_time" name="publish_time" value="{$res.end_time}">-->
                                        <!--</div>-->
                                    <!--</div>-->
                                <!--</div>-->

                                <div class="am-form-group">
                                    <label for="user-name" class="col-sm-2 control-label">广告链接 </label>
                                    <div class="am-u-sm-9">
                                        <input type="text" class="tpl-form-input" name="ad_link" id="ad_link" value="{$res.ad_link}">
                                        <small></small>
                                    </div>
                                </div>

                                    <div class="am-form-group">
                                        <label for="user-name" class="col-sm-2 control-label">广告图片 </label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" disabled="disabled" style="width:300px;margin-left:-15px;" name="ad_code" id="ad_code" value="{$res.ad_code}" >
                                            <input type="hidden" name="code_back" id="code_back" value="" >
                                        </div>
                                        <div class="col-sm-3">
                                            <input type="button" id="upload" style="color: black"  value="上传图片"/>
                                            <p><input type="file" id="f" name="f"  style="display:none"/></p>
                                        </div>
                                    </div>

                                <div class="am-form-group">
                                    <label for="user-name" class="col-sm-2 control-label"> </label>
                                    <div class="col-sm-3">
                                        <img src="{$res.ad_code}"  id="img" width="200" style="border:1pt solid #F6F6F6;">
                                    </div>

                                </div>

                                <!--<div class="am-form-group">-->
                                    <!--<label for="user-name" class="col-sm-2 control-label">背景颜色 </label>-->
                                    <!--<div class="am-u-sm-9">-->
                                        <!--<input class="form-control" name="bgcolor" id="bgcolor" type="color"  style="width:200px;" value="{$res.bgcolor}"/>-->
                                        <!--<small></small>-->
                                    <!--</div>-->
                                <!--</div>-->

                                <div class="am-form-group">
                                    <label for="user-name" class="col-sm-2 control-label">默认排序 </label>
                                    <div class="am-u-sm-9">
                                        <input type="text" class="input-sm" name="orderby" id="orderby" value="{$res.orderby}">
                                        <small></small>
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <div class="am-u-sm-9 am-u-sm-push-3">
                                        <a onclick="javascript:history.back(-1);" ><div class="btn btn-default" type="reset" >返回</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>


                                        <button class="btn btn-info" type="button" onclick="master_add()">提交</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
{include file='Public:script'}
{include file='Public:validation'}
<!--时间-->
<script src="/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script>



    $('#upload').click(function () {
        $("#f").click();
    });
    $("#f").change(function () {

        var animateimg = $("#f").val(); //获取上传的图片名 带//
        var imgarr=animateimg.split('\\'); //分割
        var myimg=imgarr[imgarr.length-1]; //去掉 // 获取图片名
        var houzui = myimg.lastIndexOf('.'); //获取 . 出现的位置
        var ext = myimg.substring(houzui, myimg.length).toUpperCase();  //切割 . 获取文件后缀

        var file = $('#f').get(0).files[0]; //获取上传的文件
        var fileSize = file.size;           //获取上传的文件大小
        var maxSize = 1048576;              //最大1MB
        if(ext !='.PNG' && ext !='.GIF' && ext !='.JPG' && ext !='.JPEG' && ext !='.BMP'){
            alert('文件类型错误,请上传图片类型');
            return false;
        }else if(parseInt(fileSize) >= parseInt(maxSize)){
            alert('上传的文件不能超过1MB');
            return false;
        }else {
            var formData = new FormData();
            formData.append("myfile", document.getElementById("f").files[0]);
            formData.append('adcode',document.getElementById('ad_code').value);
            formData.append('code_back',document.getElementById('code_back').value);
            $.ajax({
                url:'upload', /*去过那个php文件*/
                type:'POST',  /*提交方式*/
                data:formData,
                cache: false,
                contentType: false,        /*不可缺*/
                processData: false,         /*不可缺*/
                success:function(data){
                    if (data.isSuccess == true){
                        $('#ad_code').val(data.imgpath);
                        $('#code_back').val(data.imgpath);
                        $('#img').attr('src',data.imgpath);
                    }else{
                        alert(data.error);
                    }
                }
            })
        }
    });
    // 提交
    function master_add() {
        var data = new Object();
        data['ad_id'] = $('#ad_id').val();
        data['ad_name'] = $('#ad_name').val();
        data['media_type'] = $('#media_type').val();
        data['pid'] = $('#pid').val();
        data['start_time'] = $('#start_time').val();
        data['end_time'] = $('#end_time').val();
        data['ad_link']  =$('#ad_link').val();
        data['ad_code'] = $('#ad_code').val();
        data['bgcolor'] = $('#bgcolor').val();
        data['orderby'] = $('#orderby').val();
        data['code_back'] = $('#code_back').val();
        $.ajax({
            url:'edit', /*去过那个php文件*/
            type:'POST',  /*提交方式*/
            data:data,
            cache: false,
            dataType: "json",
            success:function(ret){
                if(ret.code != 200){
                    layer.msg(ret.msg, {icon: 2});
                    return false;
                }
                layer.msg(ret.msg, {icon: 1,time:2000},function(){
                    location.href = "{:url('adList')}";
                });
            }
        })
    }

    //时间插件
    $('#start_time,#end_time').daterangepicker({
        format:"YYYY-MM-DD",
        singleDatePicker: true,
        showDropdowns: true,
        minDate:'2016-01-01',
        maxDate:'2030-01-01',
        startDate:'2018-01-01',
        locale : {
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1
        }
    });




</script>

</html>